package data;

import java.sql.*;

public class ConnectToDatabase 
{
    private static Connection con = null;
    private static String url = "jdbc:sqlserver://";
   private static String serverName= "localhost";
   // private static String serverName= "RUOL-PC/SQL";
    private static String portNumber = "9999";
    private static String databaseName= "aptech";

    private static String getConnectionUrl()
    {
        //return url + serverName + ":" + portNumber + "; databaseName=" + databaseName + "; integratedSecurity=true";
        return url + serverName + ":" + portNumber + "; databaseName=" + databaseName + ";username=sa;password=sa";
    }

    public static Connection getConnection()
    {
          try
          {
               Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver"); 
               con = DriverManager.getConnection(getConnectionUrl());
          }
          catch(Exception e)
          {
              System.out.println(e);
              con = null;
          }
          return con;
     }
    
    public static void closeConnection()
    {
          try
          {
               if(con!=null)
                    con.close();
               con=null;
          }
          catch(Exception e)
          {
               e.printStackTrace();
          }
     }

    
    
}